<template>
    <Modal
        title="添加试卷"
        :width="700"
        :value="value"
        @on-ok="ok"
        @on-cancel="cancel"
    >
        <div class="paper-search">
            <Input v-model="params.paperName" placeholder="请输入试卷名称"></Input>
            <Button type="primary" @click="search">搜索</Button>
        </div>
        <Table ref="ta" :data="list" :columns="columns" highlight-row @on-current-change="changeSelect">
            <!-- <template slot-scope="{ row }" slot="radio">
                <Radio
                 v-model="row.checked"
                    @click.native="handleInput(row)"
                ></Radio>
            </template>-->
        </Table>
        <div class="content-footer">
            <Pagination
                :pageSize.sync="params.pageSize"
                :current.sync="params.pageNum"
                :total="params.total"
                @change="queryList"
            />

        </div>

    </Modal>
</template>
<script>
import { paperList } from '@/api/paper'
export default {
    props: {
        value: {
            default: ''
        },
        nowPaper: {
            default: ''
        }

    },
    data () {
        return {
            changeData: [],
            params: {
                pageNum: 1,
                pageSize: 10,
                total: 0,
                paperName: ''
            },
            list: [],
            columns: [
                { title: '序号', type: 'index', align: 'center', width: 80 },
                { title: '试卷名称', key: 'paperName', align: 'center' },
                { title: '题量', key: 'totalNum', align: 'center', width: 80 },
                { title: '总分', key: 'scores', align: 'center', width: 80 },
                { title: '建议答题时长(分钟)', key: 'totalTime', align: 'center' }
            ]
        }
    },
    created () {

    },
    activated () {
        this.queryList()
    },
    mounted () {
        this.queryList()
        console.log('paper', this.nowPaper)
    },
    methods: {
        search () {
            this.params.pageNum = 1
            this.queryList()
        },
        changeSelect (v) {
            console.log(v)
            this.changeData = v
        },
        handleInput (v) {

        },
        ok () {
            if (this.changeData.length != 0) {
                this.$emit('getPager', this.changeData)
            }
            this.$emit('hidePaper')
        },
        cancel () {
            this.$emit('hidePaper')
        },
        queryList () {
            let params = {
                pageNum: this.params.pageNum,
                pageSize: this.params.pageSize,
                paperId: '',
                paperName: this.params.paperName,
                paperNum: '',
                totalTime: ''
            }
            paperList(params).then(res => {
                console.log(this.nowPaper)
                this.list = res.data.data.list
                this.params.total = res.data.data.total
                // this.params.pageNum = res.data.data.paperNum;
                if (this.nowPaper != '') {
                    this.list.map((item, index) => {
                        if (item.paperName == this.nowPaper) {
                            this.list[index]._highlight = true
                        }
                    })
                }
            })
        }
    }
}
</script>
<style lang="less" scoped>
.content-footer{
    margin-top:15px;
}
.paper-search {
    margin-bottom: 14px;
    .ivu-input-wrapper {
        width: 300px;
        margin-right: 10px;
    }
}
</style>
